﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Core;

namespace GraphControls
{
    public partial class NewSchem : Form
    {
        private Graph _newGraph;
        private ProjectsControl _projectsControl;
        private Graph.TypeOfGraph _typeOfGraph;
        public NewSchem(ProjectsControl graph,Graph.TypeOfGraph typeOfGraph)
        {
            _typeOfGraph = typeOfGraph;
            _projectsControl = graph;
            _projectsControl.PrepToADD();
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length > 0)
            {
                if(_projectsControl.TryName(textBox1.Text))
                {
                    _newGraph = new Graph();
                    _newGraph.Name = textBox1.Text;
                    switch (_typeOfGraph)
                    {
                        case Graph.TypeOfGraph.Process:
                            {
                                _projectsControl.AddProc(_newGraph);
                                break;
                            }
                        case Graph.TypeOfGraph.Chenal:
                            {
                                _projectsControl.AddChanel(_newGraph);
                                break;
                            }
                            
                    }
                    
                    this.Close();
                }else
                {
                    MessageBox.Show(this, "Имя "+textBox1.Text + " уже занято",
                        "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                
            }
            else
            {
                MessageBox.Show(this, "Поле имя не может быть пустым", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
